import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:zrjz/comm/widget/search_app_bar.dart';

import '../../generated/assets.dart';
import '../constants/color_constants.dart';
import '../utils/dark_theme_util.dart';
import 'my_load_image.dart';

class CommonWidget {
  ///封装的默认的AppBar，Light默认模式下，黑色图标+黑色文本，Dark模式下，白色图标+白色文本
  static AppBar appBar(BuildContext context, String title,
      {void Function()? backCallback,
      String? backPath,
      Color textColor = Colors.black,
      Color backgroundColor = Colors.white,
      SystemUiOverlayStyle? systemUiOverlayStyle,
      List<Widget>? actions}) {
    return AppBar(
      systemOverlayStyle: systemUiOverlayStyle,
      leading: Container(
        padding: const EdgeInsets.only(top: 3.5),
        child: IconButton(
          icon: Get.isDarkMode
              ? MyAssetImage(backPath ?? Assets.imagesWhiteBack, width: 11, height: 18)
              : MyAssetImage(backPath ?? Assets.imagesBlackBack, width: 11, height: 18),
          onPressed: () {
            if (backCallback != null) {
              backCallback();
            } else {
              Get.back();
              // Navigator.pop(context);
            }
          },
        ),
      ),
      centerTitle: true,
      title: Text(
        title,
        style: TextStyle(color: Get.isDarkMode ? Colors.white : textColor, fontSize: 18, fontWeight: FontWeight.w600),
      ),
      actions: actions,
      backgroundColor: DarkThemeUtil.multiColors(backgroundColor, darkColor: ColorConstants.darkBlackItem),
      elevation: 0.0,
      bottom: PreferredSize(
          preferredSize: const Size.fromHeight(0.5),
          child: Divider(
            height: 0.5,
            indent: 0.0,
            color: DarkThemeUtil.multiColors(ColorConstants.dividerA6, darkColor: ColorConstants.darkBlackItemDivider),
          )),
    );
  }

  //自定义高度快
  static SizedBox rowHeight({double height = 30}) {
    return SizedBox(height: height);
  }

  //自定义宽度快
  static SizedBox rowWidth({double width = 30}) {
    return SizedBox(width: width);
  }

  /// 带搜索的AppBar
  static AppBar appSearchBar(BuildContext context,
      {void Function()? backCallback,
      String? backPath,
      Color textColor = Colors.black,
      Color backgroundColor = Colors.white,
      ValueChanged<String>? onSearch,
      ValueChanged<String>? onChanged,
      VoidCallback? onClear,
      List<Widget>? actions}) {
    return AppBar(
      // 标题与其他控件的间隔
      titleSpacing: 0,
      leadingWidth: 40,
      leading: Container(
        padding: const EdgeInsets.only(top: 3.5),
        child: IconButton(
          icon: Get.isDarkMode
              ? MyAssetImage(backPath ?? Assets.imagesWhiteBack, width: 11, height: 18)
              : MyAssetImage(backPath ?? Assets.imagesBlackBack, width: 11, height: 18),
          onPressed: () {
            if (backCallback != null) {
              backCallback();
            } else {
              Get.back();
              // Navigator.pop(context);
            }
          },
        ),
      ),
      centerTitle: true,
      title: SearchAppBar(
        onSearch: onSearch,
        onClear: onClear,
        onChanged: onChanged,
        borderRadius: 13,
        height: 28,
      ),
      actions: actions,
      backgroundColor: DarkThemeUtil.multiColors(backgroundColor),
      elevation: 0.0,
      bottom: PreferredSize(
          preferredSize: const Size.fromHeight(0.5),
          child: Divider(
            height: 1.0,
            indent: 0.0,
            color: DarkThemeUtil.multiColors(ColorConstants.dividerA6, darkColor: ColorConstants.darkBlackItemDivider),
          )),
    );
  }
}
